package com.loong.musicdemo.util;

import android.text.TextUtils;

import java.math.BigDecimal;

public class FormatTimeUtil {
    /**
     * 处理时间，将时间转化为MM：SS 格式
     * @param duration 时间以秒为单位
     * @return MM：SS 格式的字符串
     */
    public static String formatTimeToStr(int duration) {
        int time = duration / 1000;
        int min = time / 60;
        int sec = time % 60;
        String minStr, secStr = "";
        if (min < 10) {
            minStr = "0" + min;
        } else {
            minStr = min + "";
        }
        if (sec < 10) {
            secStr = "0" + sec;
        } else {
            secStr = "" + sec;
        }
        return minStr + ":" + secStr;
    }

    /**
     * 缩减数字 如255656变为 25万
     * @param str  数据字符串
     * @return 缩减后的字符串
     */
    public static String briefNumber(String str) {
        BigDecimal b1 = new BigDecimal("10000");
        BigDecimal b2 = new BigDecimal("100000000");
        BigDecimal b3 = new BigDecimal(str);
        if (b3.compareTo(b1) < 0) {//一万以下
            return str;
        } else if ((b3.compareTo(b1) == 0) || b3.compareTo(b2) < 0) {
            return str.substring(0, str.length() - 4) + "万";
        } else if (b3.compareTo(b2) >= 0) {
            return str.substring(0, str.length() - 8) + "亿";
        } else {
            return "0";
        }
    }
}
